using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WeaponStab : WeaponBase
{
    [SerializeField] private float attackTriggerDuration = .5f;

    private bool canHarm;
    private Vector2 stabDir;

    public void LaunchStab(Vector2 attackDirection)
    {
        stabDir = attackDirection.normalized;
        canHarm = true;
        Invoke(nameof(DisableHarm), attackTriggerDuration);
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (canHarm == false)
            return;

        IDamagable damagable = other.GetComponent<IDamagable>();
        if (damagable == null)
            return;

        damagable.TakeDamage(_damage, stabDir);
    }

    private void DisableHarm()
    {
        canHarm = false;
    }
}
